// packageA/detail_v2/mycomponent/goodsComponent/cloud_shop_plugin/Product_materials/Product_materials.js
const app = getApp();
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    goods_info: {
      type: null,
      value: false
    },
    goodsId: {
      type: null
    }
  },
  lifetimes: {
    attached() {
      this.getData();
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    list: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    to_materialCenter(){
      if(this.data.goods_info.brand_market.open_state == 1){
        wx.navigateTo({
          url: '/mircoApp/brand-market/brand_market/brand_source_detail/brand_source_detail?id='+this.data.list.id,
        })
        return
      }
      wx.navigateTo({
        url: '/mircoApp/cloud_shop/brand_source_detail/brand_source_detail?id='+this.data.list.id,
      })
    },
    async getData() {
      let {
        data
      } = await app._postNetWork({
        url: app.getNetAddresss("plugin.material-center.api.centerlist.index"),
        data: {
          goods_id: this.data.goodsId
        }
      })
      if (data.result) {
        if (data.data.list.data.length <= 0) {
          this.setData({
            list: null
          })
          return
        }
        this.setData({
          list: data.data.list.data[0]
        })
      } else {
        app.tips(data.msg);
      }
    }
  }
})